using System;
using System.Collections.Generic;
using MediatR;
using UniversalAdmin.Domain.Common;

namespace UniversalAdmin.Domain.Entities;       
 public abstract class EntityBase
{
  public Guid Id { get; set; } = Guid.NewGuid();

  public bool IsActive { get; set; } = true;

  public bool IsDelete { get; set; } = false;
  public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
  public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;

  private List<IDomainEvent> _domainEvents = new();
  public IReadOnlyCollection<IDomainEvent> DomainEvents => _domainEvents;
  public void AddDomainEvent(IDomainEvent eventItem) => _domainEvents.Add(eventItem);
  public void ClearDomainEvents() => _domainEvents.Clear();

  public void MarkAsDeleted()
  {
      IsDelete = true;
      UpdateTimestamps();
  }

  public void UpdateTimestamps()
  {
      UpdatedAt = DateTime.UtcNow;
  }
}
